package com.yanyeori.springtransaction.service.impl;

import com.yanyeori.springtransaction.dao.BankDao;
import com.yanyeori.springtransaction.entity.Bank;
import com.yanyeori.springtransaction.service.BankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chenkuan
 * @desc
 * @date 2021/3/10 010 19:03
 */
@Service
public class BankServiceImpl implements BankService {

    @Autowired
    BankDao bankDao;

    @Override
    public Bank select(Integer id) {
        System.out.println("查询User");
        return bankDao.select(id);
    }

    @Override
    public void add(Bank bank) {
        System.out.println("新增bank");
        bankDao.add(bank);
    }

    @Override
    public void updateNameById(Bank bank) {
        System.out.println("准备修改bank=" + bank);
        bankDao.updateNameById(bank);
    }

    @Override
    public void delete(Integer id) {
        System.out.println("删除bank");
        bankDao.delete(id);
    }

    @Override
    @Transactional
    public void transactionTest() {
        Bank bank = new Bank();
        bank.setId(1L);
        bank.setBankName("TEST_BANK_NAME_13");
        updateNameById(bank);
        //查询
        Bank select = select(1);
        System.out.println("select=" + select);
        //异常
        int n = 1 / 0;
    }
}
